/*
 * Create Author  : jinpeng.chen
 * Create Date    : 2016-11-22
 * Project        : spring-boot
 * File Name      : TaskScheduledTaskService.java
 *
 * Copyright (c) 2010-2015 by Shanghai HanTao Information Co., Ltd.
 * All rights reserved.
 *
 */
package com.charles.spring.service;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 功能描述:  <p>
 *
 * @author : jinpeng.chen <p>
 * @version 1.0 2016-11-22
 * @since spring-boot 1.0
 */
@Service
public class TaskScheduledTaskService {

    @Scheduled(fixedRate = 3000)
    public void task1() {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println("每隔3s执行一次: " + df.format(new Date()));
    }

    @Scheduled(cron = "0 47 13 ? * *")
    public void task2() {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println("在指定时间执行: " + df.format(new Date()));
    }
}
